/**
 * @file filter
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  Component,
  PropTypes
} from 'react';
import {Renderer, escapeHtml} from './renderer';
import OnExpression from './hoc/on-expression';
import Html from '../widgets/html';
import * as cx from 'classnames';

@Renderer({
  name: 'plain',
  desc: '...',
  test: (path, config) => /(?:^|\/)(?:plain|html)$/.test(path)
    || /(?:^|\/)form-item$/.test(path) && ~['plain', 'html'].indexOf(config.type)
})
@OnExpression
export default class PlainOrHtml extends Component {
  static propTypes = {
    className: PropTypes.string,
    text: PropTypes.string,
    html: PropTypes.string
  };

  static defaultProps = {
    html: ''
  };

  render() {
    const {
      formMode,
      inline,
      className,
      value,
      html,
      text
    } = this.props;

    return (
      <Html
        className={cx('plain-text', className, {
          'inline m-l-xs': inline || formMode === 'inline'
        })}
        html={value || html || text && escapeHtml(text)}
      />
    );
  }
}
